package com.hliushi.hotel.web;

import com.hliushi.hotel.service.IHotelService;
import com.hliushi.hotel.web.vo.PageResult;
import com.hliushi.hotel.web.vo.RequestVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author llhuang10
 * @date 2021/9/7 22:46
 */
@Slf4j
@RestController
@RequestMapping("/hotel")
public class HotelController {

    @Resource
    private IHotelService hotelService;


    @PostMapping("/list")
    public PageResult list(@RequestBody RequestVO requestVO) {
        PageResult result = hotelService.search(requestVO, true);
        log.info("=========== result : {}", result);
        return result;
    }

    /**
     * 需求: 前端显示的搜索的品牌, 城市等信息一开始实在vue中写死
     * 现在换成通过聚合查询索引库的酒店数据得到
     *
     * @param requestVO
     * @return PageResult
     */
    @PostMapping("/filters")
    public Map<String, List<String>> getFilters(@RequestBody RequestVO requestVO) {
        Map<String, List<String>> result = hotelService.filters(requestVO);
        log.info("=========== filtersResult : {}", result);
        return result;
    }


    /**
     * 实现酒店搜索页面输入框的自动补全
     * #
     * 前端页面, 当我们在输入框关键字时, 前端会发起ajax请求, 获取自动补全的list
     *
     * @param prefix 搜索关键字
     * @return List
     */
    @GetMapping("/suggestion")
    public List<String> getSuggestion(@RequestParam("key") String prefix) {
        List<String> result = hotelService.getSuggestion(prefix);
        log.info("=========== key = {}  suggestionResult : {}", prefix, result);
        return result;
    }
}
